using System;
using Microsoft.SmallBasic.Library;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SmallBasicFun.Tests
{
	[TestClass]
	public class EventTest
	{
		private static bool called;

		public void OnClose()
		{
			MessageBox.ShowMessage("Hello");
		}

		[TestMethod]
		public void TestName()
		{
			// Do
			Caller.FirstMethod += Method1;
			// Verify	
			Assert.AreEqual(true, called);
		}

		public static void Method1()
		{
		}

		public static void Method2()
		{
			 called = true;
		}
	}

	public class Caller
	{
		public static event SmallBasicCallback FirstMethod
		{
			add
			{
				string m2 = value.Method.Name.Replace('1', '2');
				Type type = value.Method.DeclaringType;
				type.GetMethod(m2).Invoke(value.Target, null);
			}
			remove { }
		}
	}
}